import Node from './node';

/**
 * 矩形类
 */
export default class Rect extends Node {
  className = 'Rect'; // 类名
  constructor(config = {}) {
    super(config);
    this.strokeStyle = config.strokeStyle ?? 'black';
    this.lineWidth = config.lineWidth ?? 1;
    this.lineDash = config.lineDash ?? [];
    this.fill = config.fill ?? false;
  }
  // 绘制主要内容
  drawMain(ctx) {
    const { width, height, strokeStyle, lineWidth, lineDash, fill } = this;
    // 填充矩形
    if (fill) {
      ctx.fillRect(0, 0, width, height);
    } else {
      ctx.beginPath();
      ctx.strokeStyle = strokeStyle;
      ctx.lineWidth = lineWidth;
      ctx.setLineDash(lineDash);
      ctx.rect(0, 0, width, height);
      ctx.stroke();
    }
  }
  /**
   * Methods
   */
}
